package com.t216.dm216.service.impl;

import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.t216.dm216.mapper.DmLinkUserMapper;
import com.t216.dm216.pojo.DmLinkUser;
import com.t216.dm216.service.DmLinkUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;


@Service
public class DmLinkUserServiceImpl implements DmLinkUserService {
    @Resource
    private DmLinkUserMapper dmLinkUserMapper;
    @Override
    public List<DmLinkUser> getLinkUsersByUserId(Long userId) {
        MPJLambdaWrapper<DmLinkUser> lambdaWrapper = new MPJLambdaWrapper<>();
        lambdaWrapper.select(DmLinkUser::getId,DmLinkUser::getUserId,DmLinkUser::getName,DmLinkUser::getIdCard,DmLinkUser::getCardType);
        lambdaWrapper.eq(DmLinkUser::getUserId, userId);
        return dmLinkUserMapper.selectList(lambdaWrapper);
    }

    @Override
    public Long getCountByIdCardAndUserId(DmLinkUser linkUser) {
        MPJLambdaWrapper<DmLinkUser> lambdaWrapper = new MPJLambdaWrapper<>();
        lambdaWrapper.eq(DmLinkUser::getUserId, linkUser.getUserId());
        lambdaWrapper.eq(DmLinkUser::getIdCard, linkUser.getIdCard());
        return dmLinkUserMapper.selectCount(lambdaWrapper);
    }

    @Override
    public boolean addLinkUser(DmLinkUser linkUser) {
        return dmLinkUserMapper.insert(linkUser) > 0;
    }

    @Override
    public List<DmLinkUser> getLinksUsersByIdArray(String[] idArray) {

        return dmLinkUserMapper.selectBatchIds(Arrays.asList(idArray));
    }
}
